/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lansupportclient;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;

/**
 *
 * @author Cong
 */
public class MouseController {

    private Robot robot;

    public MouseController() throws AWTException {
        robot = new Robot();
    }

    public void Clicked(int button, long x, long y) {
        int key = getKey(button);
        robot.mouseMove((int) (long) x, (int) (long) y);
        robot.mousePress(key);
    }

    public void Released(int button, long x, long y) {
        int key = getKey(button);
        robot.mouseMove((int) (long) x, (int) (long) y);
        robot.mouseRelease(key);
    }

    public void Move(long x, long y) {
        robot.mouseMove((int) (long) x, (int) (long) y);
    }

    private static int getKey(int button) {
        int key = 0;
        switch (button) {
            case 1:
                key = InputEvent.BUTTON1_DOWN_MASK;
                break;
            case 2:
                key = InputEvent.BUTTON2_DOWN_MASK;
                break;
            case 3:
                key = InputEvent.BUTTON3_DOWN_MASK;
        }
        return key;
    }
}